package com.itcoon.transform4j.demo.web.controller;

import com.itcoon.common.web.core.request.ApiRequest;
import com.itcoon.common.web.core.response.ApiResponse;
import com.itcoon.transform4j.demo.web.vo.BookVIO;
import com.itcoon.transform.starter.Transformer;
import com.itcoon.transform4j.demo.domain.Book;
import com.itcoon.transform4j.demo.web.command.BookCommand1;
import com.itcoon.transform4j.demo.web.command.BookCommand2;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "06_assemble_进阶篇", description = "临时缓存，多个转换源编集")
@RestController
@RequestMapping("/api/complex")
public class ComplexMultiSourceAssembleController {

    @ApiOperation("获取书籍")
    @PostMapping("/book1")
    public ApiResponse<BookVIO> getBook1(@RequestBody ApiRequest<BookCommand1> request){
        BookCommand1 command = request.getCommand();
        Book book = Transformer.to(Book.class).apply(command).done();
        BookVIO bookVIO = Transformer.to(BookVIO.class).apply(book).done();
        return ApiResponse.createSuccess(bookVIO);
    }

    @ApiOperation("获取书籍")
    @PostMapping("/book2")
    public ApiResponse<BookVIO> getBook2(@RequestBody ApiRequest<BookCommand2> request){
        BookCommand2 command = request.getCommand();
        Book book = Transformer.to(Book.class).apply(command).done();
        BookVIO bookVIO = Transformer.to(BookVIO.class).apply(book).done();
        return ApiResponse.createSuccess(bookVIO);
    }
}
